#include <bits/stdc++.h>
using namespace std;
int T, n, a[114514];
int main(){
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    cin >> T;
    while (T --){
        cin >> n;
        int ans = 0;
        for (int i = 1; i <= n; i ++){
            cin >> a[i];
        }
        for (int i = 1; i <= n; i ++){
            for (int j = i + 1; j <= n; j ++){
                if (a[i] == a[j]) ans += a[i];
            }
        }
        cout << ans << endl;
    }
    return 0;
}
